package com.eati.cm.utils;

import org.springframework.data.jpa.repository.JpaRepository;

import java.util.Objects;
import java.util.concurrent.Callable;


public class RPUtil {
    static public <T> void deleteIfExsits(T entity, JpaRepository repo){
        if(Objects.isNull(entity)) return;
        repo.delete(entity);
    }
    static public <T> T deleteIfExsitsAndCreateIfNoexsits(T entity, JpaRepository repo,  ICreateNewObjOperation<T> createNewObj){
        if(!Objects.isNull(entity)){
            repo.delete(entity);
        }
        return createNewObj.operation();

    }

}
